// The NSpring Framework for .NET
// Copyright (c) 2003, Jeffrey Varszegi
// All rights reserved.
// 
// Redistribution and use in source and binary forms, with or without modification, 
// are permitted provided that the following conditions are met:
// 
// - Redistributions of source code must retain the above copyright notice, this 
// list of conditions and the following disclaimer.
// 
// - Redistributions in binary form must reproduce the above copyright notice, this 
// list of conditions and the following disclaimer in the documentation and/or other 
// materials provided with the distribution.
// 
// - Neither the name of the NSpring project nor the names of its contributors may 
// be used to endorse or promote products derived from this software without 
// specific prior written permission from the copyright owner.
// 
// - No product derived from this software may be called "NSpring", nor may 
// "NSpring" appear in the name of such a product, without specific prior written 
// permission from the copyright owner.
// 
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
// IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 
// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
// OF THE POSSIBILITY OF SUCH DAMAGE. 

using System;

namespace NSpring.Logging.Loggers 
{
	using System;
	using System.Text;
	using System.Collections;

	/// <summary>
	/// <para>
	/// A Logger implementation that exists only to group child loggers; it does not write 
	/// log events to any output, but only passes them on to its children.  This can be a
	/// useful way to group several related loggers together under one buffer.
	/// </para>
	/// </summary>
	public sealed class CompositeLogger : Logger 
	{
		private static EventFormatter compositeLoggerEventFormatter = new EmptyEventFormatter();
		///// <summary>
		///// Constructs a new instance
		///// </summary>
		//public CompositeLogger() {
		//    Level = Level.All;
		//    IsBufferingEnabled = true;
		//    AutoFlushInterval = 15000;
		//    eventFormatter = compositeLoggerEventFormatter;
		//}

		///// <summary>
		///// A convenience constructor that creates and populates the CompositeLogger
		///// in one step
		///// </summary>
		///// <param name="logger1">A logger to add as a child to the CompositeLogger</param>
		//public CompositeLogger(
		//    Logger logger1
		//) : this (new Logger[] {
		//    logger1
		//}) {}

	    
		///// <summary>
		///// A convenience constructor that creates and populates the CompositeLogger
		///// in one step without the need for an array parameter
		///// </summary>
		///// <param name="logger1">A logger to add as a child to the CompositeLogger</param>
		///// <param name="logger2">A logger to add as a child to the CompositeLogger</param>
		//public CompositeLogger(
		//    Logger logger1,
		//    Logger logger2
		//) : this (new Logger[] {
		//    logger1,
		//    logger2
		//}) {}
	    
	    
		///// <summary>
		///// A convenience constructor that creates and populates the CompositeLogger
		///// in one step without the need for an array parameter
		///// </summary>
		///// <param name="logger1">A logger to add as a child to the CompositeLogger</param>
		///// <param name="logger2">A logger to add as a child to the CompositeLogger</param>
		///// <param name="logger3">A logger to add as a child to the CompositeLogger</param>
		//public CompositeLogger(
		//    Logger logger1,
		//    Logger logger2,
		//    Logger logger3
		//) : this (new Logger[] {
		//    logger1,
		//    logger2,
		//    logger3
		//}) {}
	    
	    
		///// <summary>
		///// A convenience constructor that creates and populates the CompositeLogger
		///// in one step without the need for an array parameter
		///// </summary>
		///// <param name="logger1">A logger to add as a child to the CompositeLogger</param>
		///// <param name="logger2">A logger to add as a child to the CompositeLogger</param>
		///// <param name="logger3">A logger to add as a child to the CompositeLogger</param>
		///// <param name="logger4">A logger to add as a child to the CompositeLogger</param>
		//public CompositeLogger(
		//    Logger logger1,
		//    Logger logger2,
		//    Logger logger3,
		//    Logger logger4
		//) : this (new Logger[] {
		//    logger1,
		//    logger2,
		//    logger3,
		//    logger4
		//}) {}
	    
	    
		///// <summary>
		///// A convenience constructor that creates and populates the CompositeLogger
		///// in one step without the need for an array parameter
		///// </summary>
		///// <param name="logger1">A logger to add as a child to the CompositeLogger</param>
		///// <param name="logger2">A logger to add as a child to the CompositeLogger</param>
		///// <param name="logger3">A logger to add as a child to the CompositeLogger</param>
		///// <param name="logger4">A logger to add as a child to the CompositeLogger</param>
		///// <param name="logger5">A logger to add as a child to the CompositeLogger</param>
		//public CompositeLogger(
		//    Logger logger1,
		//    Logger logger2,
		//    Logger logger3,
		//    Logger logger4,
		//    Logger logger5
		//) : this (new Logger[] {
		//    logger1,
		//    logger2,
		//    logger3,
		//    logger4,
		//    logger5
		//}) {}
	    
	    
		///// <summary>
		///// A convenience constructor that creates and populates the CompositeLogger
		///// in one step without the need for an array parameter
		///// </summary>
		///// <param name="logger1">A logger to add as a child to the CompositeLogger</param>
		///// <param name="logger2">A logger to add as a child to the CompositeLogger</param>
		///// <param name="logger3">A logger to add as a child to the CompositeLogger</param>
		///// <param name="logger4">A logger to add as a child to the CompositeLogger</param>
		///// <param name="logger5">A logger to add as a child to the CompositeLogger</param>
		///// <param name="logger6">A logger to add as a child to the CompositeLogger</param>
		//public CompositeLogger(
		//    Logger logger1,
		//    Logger logger2,
		//    Logger logger3,
		//    Logger logger4,
		//    Logger logger5,
		//    Logger logger6
		//) : this (new Logger[] {
		//    logger1,
		//    logger2,
		//    logger3,
		//    logger4,
		//    logger5,
		//    logger6
		//}) {}
	    
	    
		///// <summary>
		///// A convenience constructor that creates and populates the CompositeLogger
		///// in one step without the need for an array parameter
		///// </summary>
		///// <param name="logger1">A logger to add as a child to the CompositeLogger</param>
		///// <param name="logger2">A logger to add as a child to the CompositeLogger</param>
		///// <param name="logger3">A logger to add as a child to the CompositeLogger</param>
		///// <param name="logger4">A logger to add as a child to the CompositeLogger</param>
		///// <param name="logger5">A logger to add as a child to the CompositeLogger</param>
		///// <param name="logger6">A logger to add as a child to the CompositeLogger</param>
		///// <param name="logger7">A logger to add as a child to the CompositeLogger</param>
		//public CompositeLogger(
		//    Logger logger1,
		//    Logger logger2,
		//    Logger logger3,
		//    Logger logger4,
		//    Logger logger5,
		//    Logger logger6,
		//    Logger logger7
		//) : this (new Logger[] {
		//    logger1,
		//    logger2,
		//    logger3,
		//    logger4,
		//    logger5,
		//    logger6,
		//    logger7
		//}) {}
	    
	    
		///// <summary>
		///// A convenience constructor that creates and populates the CompositeLogger
		///// in one step without the need for an array parameter
		///// </summary>
		///// <param name="logger1">A logger to add as a child to the CompositeLogger</param>
		///// <param name="logger2">A logger to add as a child to the CompositeLogger</param>
		///// <param name="logger3">A logger to add as a child to the CompositeLogger</param>
		///// <param name="logger4">A logger to add as a child to the CompositeLogger</param>
		///// <param name="logger5">A logger to add as a child to the CompositeLogger</param>
		///// <param name="logger6">A logger to add as a child to the CompositeLogger</param>
		///// <param name="logger7">A logger to add as a child to the CompositeLogger</param>
		///// <param name="logger8">A logger to add as a child to the CompositeLogger</param>
		//public CompositeLogger(
		//    Logger logger1,
		//    Logger logger2,
		//    Logger logger3,
		//    Logger logger4,
		//    Logger logger5,
		//    Logger logger6,
		//    Logger logger7,
		//    Logger logger8
		//) : this (new Logger[] {
		//    logger1,
		//    logger2,
		//    logger3,
		//    logger4,
		//    logger5,
		//    logger6,
		//    logger7,
		//    logger8
		//}) {}
	    
	    
		///// <summary>
		///// A convenience constructor that creates and populates the CompositeLogger
		///// in one step without the need for an array parameter
		///// </summary>
		///// <param name="logger1">A logger to add as a child to the CompositeLogger</param>
		///// <param name="logger2">A logger to add as a child to the CompositeLogger</param>
		///// <param name="logger3">A logger to add as a child to the CompositeLogger</param>
		///// <param name="logger4">A logger to add as a child to the CompositeLogger</param>
		///// <param name="logger5">A logger to add as a child to the CompositeLogger</param>
		///// <param name="logger6">A logger to add as a child to the CompositeLogger</param>
		///// <param name="logger7">A logger to add as a child to the CompositeLogger</param>
		///// <param name="logger8">A logger to add as a child to the CompositeLogger</param>
		///// <param name="logger9">A logger to add as a child to the CompositeLogger</param>
		//public CompositeLogger(
		//    Logger logger1,
		//    Logger logger2,
		//    Logger logger3,
		//    Logger logger4,
		//    Logger logger5,
		//    Logger logger6,
		//    Logger logger7,
		//    Logger logger8,
		//    Logger logger9
		//) : this (new Logger[] {
		//    logger1,
		//    logger2,
		//    logger3,
		//    logger4,
		//    logger5,
		//    logger6,
		//    logger7,
		//    logger8,
		//    logger9
		//}) {}
	    
	    
		///// <summary>
		///// A convenience constructor that creates and populates the CompositeLogger
		///// in one step without the need for an array parameter
		///// </summary>
		///// <param name="logger1">A logger to add as a child to the CompositeLogger</param>
		///// <param name="logger2">A logger to add as a child to the CompositeLogger</param>
		///// <param name="logger3">A logger to add as a child to the CompositeLogger</param>
		///// <param name="logger4">A logger to add as a child to the CompositeLogger</param>
		///// <param name="logger5">A logger to add as a child to the CompositeLogger</param>
		///// <param name="logger6">A logger to add as a child to the CompositeLogger</param>
		///// <param name="logger7">A logger to add as a child to the CompositeLogger</param>
		///// <param name="logger8">A logger to add as a child to the CompositeLogger</param>
		///// <param name="logger9">A logger to add as a child to the CompositeLogger</param>
		///// <param name="logger10">A logger to add as a child to the CompositeLogger</param>
		//public CompositeLogger(
		//    Logger logger1,
		//    Logger logger2,
		//    Logger logger3,
		//    Logger logger4,
		//    Logger logger5,
		//    Logger logger6,
		//    Logger logger7,
		//    Logger logger8,
		//    Logger logger9,
		//    Logger logger10
		//) : this (new Logger[] {
		//    logger1,
		//    logger2,
		//    logger3,
		//    logger4,
		//    logger5,
		//    logger6,
		//    logger7,
		//    logger8,
		//    logger9,
		//    logger10
		//}) {}
	    
	    
	    

		/// <summary>
		/// Constructs a new instance, adding the loggers in the passed array as children 
		/// </summary>
		/// <param name="children">The array of child loggers to add to the new CompositeLogger</param>
		public CompositeLogger(params Logger[] children) 
		{
			if (children == null) {
				children = new Logger[] {};
			}
			Logger child;
			for(int x = 0; x < children.Length; x++) {
				child = children[x];
				if (child != null) {
					AddChild(child);
				}
			}
			Level = Level.All;
			IsBufferingEnabled = true;
			AutoFlushInterval = 15000;
			eventFormatter = compositeLoggerEventFormatter;
		}
	    
		protected override void Write(Event _event) {}

		protected override void Write(Event[] _events, int _length) {}
	    
		private sealed class EmptyEventFormatter : EventFormatter {
			private const string BLANK_STRING               = "";

			public override string Format(Event _event) {
				return BLANK_STRING;
			}
	        
			public override string GetEventListHeader() {
				return null;
			}

			public override string GetEventListFooter() {
				return null;
			}
		}
	    
	}

}
